using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Voodoo.Distribution;
using Voodoo.Pattern;

public class Progress : SingletonMB<Progress>
{
	[SerializeField]
	private Slider _slider;

	[SerializeField]
	private DynamicFilledImage fill;

	[SerializeField]
	private TextMeshProUGUI _level;

	[SerializeField]
	private GameObject _endFlag;

	[SerializeField]
	private TMP_Text _textProgress;

	[SerializeField]
	private DuelModeProgressUI DuelModeProgress;

	private int maxCount;

	private int currentCount;

	private float step;

	private bool _moreThanThird;

	private int DestroyedByPlayer;

	private int DestroyedByOpponent;

	private void Start()
	{
		_level.text = string.Format(Localization.GetTranslation("Generic_Level"), NintendoPlayerPrefs.GetInt("Level", 0) + 1);
	}

	public void SetLevelText(int level)
	{
		_level.text = string.Format(Localization.GetTranslation("Generic_Level"), level);
	}

	public int Pr()
	{
		return (int)(fill.FillAmount * 100f);
	}

	public int GetMaxCount()
	{
		return maxCount;
	}

	public void SetMaxCount(int count)
	{
		maxCount = count;
		currentCount = maxCount - 10;
		step = 1f / (float)currentCount;
	}

	public void KillBlock()
	{
		if (currentCount - 1 > 0)
		{
			currentCount--;
			fill.FillAmount += step;
			DestroyedByPlayer++;
			if (Preloader.OptimizationConfig.IsEnabled && !_moreThanThird && fill.FillAmount > 0.33f)
			{
				Time.maximumDeltaTime = 0.04f;
				_moreThanThird = true;
			}
		}
		else
		{
			GetComponent<GameManager>().FinishLevel();
		}
		if ((double)fill.FillAmount >= 0.94)
		{
			GetComponent<GameManager>().FinishLevel();
		}
	}

	public void ResetCount()
	{
		currentCount = maxCount - 10;
		fill.FillAmount = 0f;
		if (Preloader.OptimizationConfig.IsEnabled)
		{
			Time.maximumDeltaTime = 0.06f;
		}
		_moreThanThird = false;
	}

	internal void KillBlockOpponent()
	{
		if (currentCount - 1 > 0)
		{
			currentCount--;
			_slider.value += step;
			_textProgress.text = $"{Mathf.Ceil(_slider.value * 100f)}%";
			DestroyedByOpponent++;
		}
	}
}
